package com.example.guestbook.servlet;

import com.example.guestbook.pojo.Booklist;
import com.example.guestbook.service.IBooklistService;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

@WebServlet("/addbook")
public class AddBookServlet extends HttpServlet
{



    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        // 用户提交来的编码
        req.setCharacterEncoding("utf-8");
        // 设置响应内容
        resp.setContentType("text/html;charset=utf-8");

        PrintWriter pw = resp.getWriter();


        // 1. 获取参数
        String username = req.getParameter("username");
        String title = req.getParameter("title");
        String note = req.getParameter("note");
        String face = req.getParameter("face");
//        private Integer bookid;
//
//        private String username;
//
//        private String booktitle;
//
//        private String bookface;
//
//        private Date booktime;
//
//        private String bookip;
//
//        private String booknote;

        pw.println(username);
        pw.println(title);

        // 2. 调用下层
        // 得到Spring从容器,
        // 从容器中获取customerServcie的Bean
        WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
        IBooklistService booklistService = (IBooklistService)applicationContext.getBean("booklistServet");






        // 3. 跳转 或 请求转发
    }
}